/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CastleDefense.units;

import CastleDefense.Animation;
import CastleDefense.Game;
import java.awt.Image;
import javax.vecmath.Vector2d;

/**
 *
 * @author Firedemon
 */
public class Blowgunist extends PlacedUnit
{
    private Animation BlowgunistAnimation;

    public Blowgunist(Vector2d location, Image sprite)
    {
        super(location, sprite, "Blowgunist");

        BlowgunistAnimation = new Animation(getAnimation("Blowgunist"), 1000);
        this.setAnimation(BlowgunistAnimation);
    }

    @Override
    public void doLogic()
    {
        if(getTarget() != null && !getTarget().isDead() && !getTarget().isPoisoned())
        {
            targetD = distance(getLoc().x, getLoc().y, getTarget().getMidX(), getTarget().getMidY());
            if(targetD > range)
            {
                setClosestTarget();
                return;
            }

            if(System.currentTimeMillis() - lastFire < rateOfFire)
                return;

            lastFire = System.currentTimeMillis();
            Game.fireAtEnemy(getTarget(), this);
        }
        else
        {
            setClosestTarget();
        }
    }
}
